package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.applyAgentBean;
import com.ymatou.iapi.godmch.parameter.approveAgentBean;
import com.ymatou.iapi.godmch.parameter.auditAgentLogBean;
import com.ymatou.iapi.godmch.parameter.reApplyAgentBean;
import com.ymatou.iapi.godmch.parameter.rejectAgentBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.auditAgentLogCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
/**
*代理审核日志列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_auditAgentLog{
	private static auditAgentLogBean bean;
	private static auditAgentLogCall call;
	
	agent_typeWapper agentTypeWapper=new agent_typeWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("代理审核日志列表");
	}

	@Before
	public void caseUp() {
		bean=new auditAgentLogBean();
		call=new auditAgentLogCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_001() {
		Logger.start(true,"正例-代理审核日志列表-1：代理申请");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();			
			
			org.json.JSONObject jObject=new org.json.JSONObject(call.getList().get(0).toString());
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(1, call.getTotal(), "验证total");
			Logger.verifyEquals(1, Integer.parseInt(jObject.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject.get("remark"), "验证remark");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_001_1() {
		Logger.start(true,"正例-代理审核日志列表-2：渠道商审核通过");
		try {
			//代理申请
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//查询代理类型
			Map<String,Object> map=new HashMap();
			map.put("mchId", applyBean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//审核通过
			approveAgentBean approveBean=GodmchManageCallService.InitApproveAgentBean();
			approveBean.setMchId(applyBean.getMchId());
			approveBean.setAgentId(applyCall.getAgentId());
			approveBean.setAgentType(list.get(0).getAgentType());
			GodmchManageCallService.ApproveAgentCall(approveBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(2, call.getTotal(), "验证total");
			org.json.JSONObject jObject1=new org.json.JSONObject(call.getList().get(0).toString());
			org.json.JSONObject jObject2=new org.json.JSONObject(call.getList().get(1).toString());

			Logger.verifyEquals(2, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
			Logger.verifyEquals("审核通过", jObject1.get("remark"), "验证remark");		
			Logger.verifyEquals(1, Integer.parseInt(jObject2.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject2.get("remark"), "验证remark");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_001_2() {
		Logger.start(true,"正例-代理审核日志列表-3：渠道商审核拒绝");
		try {
			//代理申请
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(2, call.getTotal(), "验证total");
			org.json.JSONObject jObject1=new org.json.JSONObject(call.getList().get(0).toString());
			org.json.JSONObject jObject2=new org.json.JSONObject(call.getList().get(1).toString());

			Logger.verifyEquals(3, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
			Logger.verifyEquals(rejectBean.getReason(), jObject1.get("remark"), "验证remark");		
			Logger.verifyEquals(1, Integer.parseInt(jObject2.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject2.get("remark"), "验证remark");				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_001_3() {
		Logger.start(true,"正例-代理审核日志列表-4：渠道商移除代理关系");
		try {
			
			//代理申请
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//查询代理类型
			Map<String,Object> map=new HashMap();
			map.put("mchId", applyBean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//审核通过
			approveAgentBean approveBean=GodmchManageCallService.InitApproveAgentBean();
			approveBean.setMchId(applyBean.getMchId());
			approveBean.setAgentId(applyCall.getAgentId());
			approveBean.setAgentType(list.get(0).getAgentType());
			GodmchManageCallService.ApproveAgentCall(approveBean);
			//移除关系
			GodmchManageCallService.InitremovemchForAgent(applyBean.getMchId(),applyCall.getAgentId());
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(3, call.getTotal(), "验证total");
			org.json.JSONObject jObject1=new org.json.JSONObject(call.getList().get(0).toString());
			org.json.JSONObject jObject2=new org.json.JSONObject(call.getList().get(1).toString());
			org.json.JSONObject jObject3=new org.json.JSONObject(call.getList().get(2).toString());

			Logger.verifyEquals(4, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
			Logger.verifyEquals("渠道商移除代理关系", jObject1.get("remark"), "验证remark");		
			Logger.verifyEquals(2, Integer.parseInt(jObject2.get("logType").toString()), "验证logType");
			Logger.verifyEquals("审核通过", jObject2.get("remark"), "验证remark");	
			Logger.verifyEquals(1, Integer.parseInt(jObject3.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject3.get("remark"), "验证remark");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_001_4() {
		Logger.start(true,"正例-代理审核日志列表-移除关系-重新申请-4：渠道商移除代理关系");
		try {
			
			//代理申请
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//查询代理类型
			Map<String,Object> map=new HashMap();
			map.put("mchId", applyBean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//审核通过
			approveAgentBean approveBean=GodmchManageCallService.InitApproveAgentBean();
			approveBean.setMchId(applyBean.getMchId());
			approveBean.setAgentId(applyCall.getAgentId());
			approveBean.setAgentType(list.get(0).getAgentType());
			GodmchManageCallService.ApproveAgentCall(approveBean);
			//移除关系
			GodmchManageCallService.InitremovemchForAgent(applyBean.getMchId(),applyCall.getAgentId());
			//重新申请
			reApplyAgentBean reApplyAgentBean=GodmchManageCallService.initReApplyAgentBean(applyBean.getMchId(),applyCall.getAgentId());
			GodmchManageCallService.reApplyAgentCall(reApplyAgentBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(4, call.getTotal(), "验证total");
			org.json.JSONObject jObject1=new org.json.JSONObject(call.getList().get(0).toString());
			org.json.JSONObject jObject2=new org.json.JSONObject(call.getList().get(1).toString());
			org.json.JSONObject jObject3=new org.json.JSONObject(call.getList().get(2).toString());
			org.json.JSONObject jObject4=new org.json.JSONObject(call.getList().get(3).toString());

			Logger.verifyEquals(1, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
			Logger.verifyEquals("重新提交代理申请", jObject1.get("remark"), "验证remark");		
			Logger.verifyEquals(4, Integer.parseInt(jObject2.get("logType").toString()), "验证logType");
			Logger.verifyEquals("渠道商移除代理关系", jObject2.get("remark"), "验证remark");		
			Logger.verifyEquals(2, Integer.parseInt(jObject3.get("logType").toString()), "验证logType");
			Logger.verifyEquals("审核通过", jObject3.get("remark"), "验证remark");	
			Logger.verifyEquals(1, Integer.parseInt(jObject4.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject4.get("remark"), "验证remark");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_001_5() {
		Logger.start(true,"正例-代理审核日志列表-拒绝-重新申请-4：渠道商移除代理关系");
		try {
			
			//代理申请
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
	
			//拒绝
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			//重新申请
			reApplyAgentBean reApplyAgentBean=GodmchManageCallService.initReApplyAgentBean(applyBean.getMchId(),applyCall.getAgentId());
			GodmchManageCallService.reApplyAgentCall(reApplyAgentBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(3, call.getTotal(), "验证total");
			org.json.JSONObject jObject1=new org.json.JSONObject(call.getList().get(0).toString());
			org.json.JSONObject jObject2=new org.json.JSONObject(call.getList().get(1).toString());
			org.json.JSONObject jObject3=new org.json.JSONObject(call.getList().get(2).toString());

			Logger.verifyEquals(1, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
			Logger.verifyEquals("重新提交代理申请", jObject1.get("remark"), "验证remark");			
			Logger.verifyEquals(3, Integer.parseInt(jObject2.get("logType").toString()), "验证logType");
			Logger.verifyEquals(rejectBean.getReason(), jObject2.get("remark"), "验证remark");	
			Logger.verifyEquals(1, Integer.parseInt(jObject3.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject3.get("remark"), "验证remark");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_002() {
		Logger.start(true,"正例-代理审核日志列表-mchId不存在");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId()+1);
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(0, call.getTotal(), "验证total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_003() {
		Logger.start(true,"正例-代理审核日志列表-mchId为空");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(null);
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_004() {
		Logger.start(true,"正例-代理审核日志列表-agentId不存在");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId()+1);
			bean.setPageIndex(1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(0, call.getTotal(), "验证total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_005() {
		Logger.start(true,"正例-代理审核日志列表-agentId为空");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(null);
			bean.setPageIndex(1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_006() {
		Logger.start(true,"正例-代理审核日志列表-pageIndex等于0");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(0);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_007() {
		Logger.start(true,"正例-代理审核日志列表-pageIndex等于-1");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(-1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_008() {
		Logger.start(true,"正例-代理审核日志列表-pageIndex为空");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(null);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_009() {
		Logger.start(true,"正例-代理审核日志列表-pageSize等于0");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(0);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_010() {
		Logger.start(true,"正例-代理审核日志列表-pageSize等于-1");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(-1);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_011() {
		Logger.start(true,"正例-代理审核日志列表-pageSize为空");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(1);
			bean.setPageSize(null);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_012() {
		Logger.start(true,"正例-代理审核日志列表-显示第二页");
		try {
			//代理申请
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//查询代理类型
			Map<String,Object> map=new HashMap();
			map.put("mchId", applyBean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//审核通过
			approveAgentBean approveBean=GodmchManageCallService.InitApproveAgentBean();
			approveBean.setMchId(applyBean.getMchId());
			approveBean.setAgentId(applyCall.getAgentId());
			approveBean.setAgentType(list.get(0).getAgentType());
			GodmchManageCallService.ApproveAgentCall(approveBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(2);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(2, call.getTotal(), "验证total");
			org.json.JSONObject jObject1=new org.json.JSONObject(call.getList().get(0).toString());
//			org.json.JSONObject jObject2=new org.json.JSONObject(call.getList().get(1).toString());
//
//			Logger.verifyEquals(2, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
//			Logger.verifyEquals("审核通过", jObject1.get("remark"), "验证remark");		
			Logger.verifyEquals(1, Integer.parseInt(jObject1.get("logType").toString()), "验证logType");
			Logger.verifyEquals("申请代理", jObject1.get("remark"), "验证remark");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_auditAgentLog_013() {
		Logger.start(true,"正例-代理审核日志列表-下一页为空,总条数1条,pageIndex=3,pageSize=1");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setPageIndex(3);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(1, call.getTotal(), "验证total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}